# -*- coding: utf-8 -*--

HORIZONTAL, VERTICAL = "H", "V"
WEST, EAST, NORTH, SOUTH = "W", "E", "N", "S"

EMPTY, WALL = "0", "1"

class Map:
  def __init__(self, coordonate ):
    self.__coordonate = coordonate
    self.__length = coordonate[0]*coordonate[1]
    self.clear()
    
  def indexToCoordonate(self, index):
    return ( int( index % self.__coordonate[0] ), int( index / self.__coordonate[0] ) )
  
  def coordonateToIndex(self, coordonate):
    return self.__coordonate[0] * coordonate[1] + coordonate[0]
  
  def getSurface(self):
    return self.__surface
  
  def clear(self):
    self.__surface = list(EMPTY*self.__length )
  
  def addWall(self, coordonate, length, orientation, direction ):
    self.__surface[self.coordonateToIndex(coordonate)] = WALL
    for i in range(length):
      if orientation == HORIZONTAL:
        if direction == WEST:
          self.__surface[self.coordonateToIndex((coordonate[0]-i, coordonate[1]))] = WALL
        elif direction == EAST:
          self.__surface[self.coordonateToIndex((coordonate[0]+i, coordonate[1]))] = WALL
        else:
          raise "error"
      elif  orientation == VERTICAL:
        if direction == NORTH:
          self.__surface[self.coordonateToIndex((coordonate[0], coordonate[1]-i))] = WALL
        elif direction == SOUTH:
          self.__surface[self.coordonateToIndex((coordonate[0], coordonate[1]+i))] = WALL
        else:
          raise "error"
      
  def hasWall(self, coordonate):
    return (self.__surface[self.coordonateToIndex(coordonate)] == WALL)